@extends("backend.layout.main")



@section("right_content")
    <!--middle-->
    <div class="mainWrapBox">
        <div class="mainBox">
			
<h1><a href="comset/index.htm">公司设置</a> / 项目设置</h1>
	<div class="html">
<div class="w220 f_l">
    <div class="listWrapbox mt10" id="main-left" style="padding: 0px; height: 793px;">
        <h2 style="padding: 0 20px;">项目设置</h2>
        <ul class="setting-menu">
            <li class="current"><a href="业务参数设置.html">业务参数设置</a></li>
            <li><a href="项目角色设置.html">项目角色设置</a></li>
           <li><a href="项目模板设置.html">项目模板设置</a></li>
          <li><a href="员工职级设置.html">员工职级设置</a></li>
        </ul>
    </div>
</div>
		<div class="auto-width-220">
			<div class="listWrapbox mt10" id="main-right">
			<h2>业务参数设置</h2>
				<div class="inbox-one">
					<div class="inbox-nav"><span>项目类型</span></div>
					<div class="inbox-input">



			<input placeholder="输入项目类型,按回车提交" class="set-input addProjectSet" maxlength="30" type="text" id="">



                    </div>
                    @foreach( $type as $t )

                                <div onmouseout="hide_tag(this);" onmousemove="remove_tag(this);">
                                <div class="inbox-list" style="padding: 0px;height: 35px;line-height: 35px;">{{ $t->type_name }}</div>
                    <input  type="button" data="{{ $t->type_id }}" class="btn1" style="display: none" id="1">
								</div>
                    @endforeach    
                               
                               
                               
                                
				</div>
                <div class="inbox-one">
                    <div class="inbox-nav"><span>项目阶段</span></div>
                    <div class="inbox-input">
                        <input placeholder="输入项目阶段,按回车提交" class="set-input addProjectSet" maxlength="30" type="text" id="">
                    </div>
                           @foreach( $phase as $p )
                          
                                <div onmouseout="hide_tag(this);" onmousemove="remove_tag(this);">
                        <div class="inbox-list" style="padding: 0px;height: 35px;line-height: 35px;">{{ $p->phase_name }}</div>
                        <input type="button" class="btn1" data="{{ $p->phase_id }}" style="display: none" id="2">
                                </div>
                            @endforeach                                     
                                
                </div>				



                <div class="inbox-one">
					<div class="inbox-nav"><span>员工职级设置</span></div>
					<div class="inbox-input">
						<input placeholder="输入项目阶段,按回车提交" class="set-input addProjectSet" maxlength="30" type="text" id="">
					</div>


					       @foreach( $staff as $f )
					      
                            	<div onmouseout="hide_tag(this);" onmousemove="remove_tag(this);">
						<div class="inbox-list" style="padding: 0px;height: 35px;line-height: 35px;">{{ $f->position_name }}</div>
                        <input type="button" class="btn1" data="{{ $f->sid }}" style="display: none" id="3">
								</div>
                            @endforeach	      	                          	
                            	
				</div>




				
			</div>
		</div>
	</div>
 <script type="text/javascript">
		/* * 隐藏删除按钮
		 * @param obj
		 */
		function hide_tag(obj){

			$(obj).find("input[type='button']").hide();

		}

		/**
		 * 显示删除按钮
		 * @param obj
		 */
		function remove_tag(obj){
           
            $(obj).find("input[type='button']").show();
		}

    </script>

    <script type="text/javascript">
        $(function () {
			$(document).on('click',function(){
			$(".btn1").click(function(){
			
                    var that = $(this);


                       
					$.ajax({
						type : "get",
						url : "/backend/prophasedel",
						data : {
							'did':that.attr("data"),
                            'id':that.attr("id")
						},
	
						dataType : "json",
						success : function(data) {
							if(data.flag != 1){
							  
								that.prev().remove();
							    //that.remove();
							}else{
								alert("删除失败");
							}
		  
						}
						
					});
			     })
			})
		});
            init();

			$(".inbox-list").bind("click",function(){
                var len = $(this).find("input").length;
						if(len==0){
							var txt = $(this).text();
							var html = '<input type="text" class="input updateProjectSet" maxlength="30" value="'+txt+'" style="border: 0px;height: 31px;width: 208px;font-size:12px">';
							$(this).html(html);
							$(this).css("text-indent","0");
							$(this).find("input")[0].focus();
						}
			});
      
		function init(){
            $(document).on('blur','.updateProjectSet',function(e){
                changeTxt(this);
            });
		}

		function changeTxt(obj){
			var txt = $(obj).val();
            var type = $(obj).parent().parent().parent().children().first().find("span").text();
			var isNotNullOrRepeat = true;
			if(txt == ''){
				alert(type+"必填");
				isNotNullOrRepeat = false;
			}else if(txt.length>30){
                alert("长度不能超过30个字符");
                isNotNullOrRepeat = false;
            }else{
                $(obj).parent().parent().siblings().not(".inbox-nav,.inbox-input").each(function(){
					var inbox = $(this).find(".inbox-list").text();
					if(inbox == txt){
						isNotNullOrRepeat = false;
						return;
					}
				});
			}

			if(isNotNullOrRepeat){
				var id = $(obj).parent().next().attr("data");
                $.ajax({
                    type : "POST",
                    url : "",
                    data : {
                        'id':id,
						'name':txt
                    },
                    async : false,
                    dataType : "json",
                    success : function(data) {
                        if(data.flag == 1){
							 var $p = $(obj).parent();
				             $p.html(txt);
				             $p.css("text-indent","0.5em");
                        }else{
                            //alert("保存失败");
                        }
                    }
                });
			}

		}

       $(document).on('keypress','.addProjectSet',function(e){			  
            
            var e=e || event;
            keycode=e.which || e.keyCode;
			//当按下enter健时，保存。
            if(keycode==13){
			    saveSetting(this);
            }
        });

        function check(obj){
            var txt = $.trim($(obj).val());
			var type = $(obj).parent().prev().find("span").text();
			var isNotNullOrRepeat = true;
			if(txt==''){g
				alert(type+"必填");
                isNotNullOrRepeat = false;
			}else if(txt.length>30){
				alert("长度不能超过30个字符");
                isNotNullOrRepeat = false;
			}else{
				$(obj).parent().parent().find(".inbox-list").each(function(){
					var inbox = $(this).text();
					if(inbox == txt){
						alert(type+"不能重复");
                        isNotNullOrRepeat = false;
						return;
					}
				});
			}

            return isNotNullOrRepeat;
        }

        function saveSetting(obj){

            if(check(obj)){
                var txt = $(obj).parent().prev().find("span").text();
				var inbox = $.trim($(obj).val());
                var type = 1;
                var id = $(obj).attr('id');
                //alert(id);
				if(txt == '项目类型'){
					type = 1;
				}else if(txt == '项目阶段'){
					type = 2;
				}else{
                    type = 3;
                }
       
                    $.ajax({
                        
                        url : "/backend/prophasemsg",
                        type : "get",
                        data : {
                            'type':type,
    						'name':inbox,
    						'orgId': id
                        },
                        dataType : "json",
                    success : function(e) {

                    if( type==1 ){


                    var html="<div onmouseout='hide_tag(this);'onmousemove='remove_tag(this);'><div class='inbox-list'style='padding: 0px;height: 35px;line-height: 35px;'>"+inbox+"</div><input type='button' class='btn1'data='999' style='display: none'></div>";
							
					$(".inbox-one:first").append(html);

                    }else if( type==2 ){

                        var html="<div onmouseout='hide_tag(this);' onmousemove='remove_tag(this);'><div class='inbox-list'style='padding: 0px;height: 35px;line-height: 35px;'>"+inbox+"</div><input type='button' class='btn1'data='999' style='display: none'></div>";
                    
                           $(".inbox-one:eq(1)").append(html);
                       }else{

						var html="<div onmouseout='hide_tag(this);' onmousemove='remove_tag(this);'><div class='inbox-list'style='padding: 0px;height: 35px;line-height: 35px;'>"+inbox+"</div><input type='button' class='btn1'data='999' style='display: none'></div>";
					
					       $(".inbox-one:last").append(html);
                       }						
					
					},
					
				});
				}
			}
       	
</script>
  
        </div>
    </div>
</div>
</div>
@endsection
